Release 10.1A: OpenEdge Development:
Messaging and ESB


Publishing with message properties and subscribing selectively

The procedure example3.p publishes a TextMessage from Super Golf Center to Sub Par Golf using the setStringProperty procedure. The procedure example4.p (1 of 2) subscribes to a topic and only receives messages addressed to Sub Par Golf (by passing a selector to the subscribe procedure call).

To run example3.p and example4.p:

  1. Run example4.p (1 of 2) first so the subscriber is running before you publish, as shown:
  2. example4.p
    /* Receives a Text message with the "TO" property equals to "Sub Par Golf" 
    */ 
    DEFINE VARIABLE pubsubsession AS HANDLE. 
    DEFINE VARIABLE consumerH AS HANDLE. 
    /* Creates a session object. */ 
    RUN jms/pubsubsession.p PERSISTENT SET pubsubsession  
                                      ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN pubsubsession ("localhost:2506"). 
    RUN beginSession IN pubsubsession. 
    /* Subscribes to the GolfTopic topic. Messages are handled by the 
       "golfHandler" internal procedure.  */ 
    RUN createMessageConsumer IN pubsubsession ( 
                          THIS-PROCEDURE,   /* This proc will handle it */ 
                          "golfHandler",    /* name of internal procedure */ 
                          OUTPUT consumerH). 
    RUN subscribe IN pubsubsession (
                 "GolfTopic",           /* name of topic */ 
                 ?,                     /* Subscription is not durable */ 
                 "TO = 'Sub Par Golf'",  /* Only messages from Sub Par Golf */ 
                 no,                    /* Want my own messages too */ 
                 consumerH).            /* Handles the incoming messages */ 
    /* Start receiving messages */ 
    RUN startReceiveMessages IN pubsubsession. 
    /* Wait to receive the messages. Any other IO-blocked statements can be
       used for receiving messages.  
    */ 
    WAIT-FOR u1 OF THIS-PROCEDURE. 
    
    PROCEDURE golfHandler: 
    DEFINE INPUT PARAMETER messageH AS HANDLE. 
    DEFINE INPUT PARAMETER msgConsumerH AS HANDLE. 
    DEFINE OUTPUT PARAMETER replyH AS HANDLE. 
        /* Display the message - we assume that reply is not required. */ 
        DISPLAY "Message text: " DYNAMIC-FUNCTION('getText':U IN messageH) 
                                 FORMAT "X(30)" 
           "Message from: " DYNAMIC-FUNCTION('getCharProperty':U IN 
                                              messageH, 
                                              "FROM"). 
        RUN deleteMessage IN messageH. 
        APPLY "U1" TO THIS-PROCEDURE. 
    END. 
    

  3. Run example3.p, as shown:
  4. example3.p
    /* Publishes a Text message with properties. */ 
    DEFINE VARIABLE pubsubsession AS HANDLE. 
    DEFINE VARIABLE messageH AS HANDLE. 
    /* Creates a session object. */ 
    RUN jms/pubsubsession.p PERSISTENT SET pubsubsession  
                                      ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN pubsubsession ("localhost:2506"). 
    RUN beginSession IN pubsubsession. 
    /* Create a text message */ 
    RUN createTextMessage IN pubsubsession (OUTPUT messageH). 
    RUN setText IN messageH ("Golf shoes on sale today."). 
    /* Set the "FROM:" and the "TO:" properties */ 
    RUN setStringProperty IN messageH ("FROM", "Super Golf Center"). 
    RUN setStringProperty IN messageH ("TO", "Sub Par Golf"). 
    /* Publish the message on to the golf topic */ 
    RUN publish IN pubsubsession ("GolfTopic", messageH, ?, ?, ?). 
    


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095